
const MpesaKesPageTag = require("./mpesaKesPageTag.js");
const Constant = require("./constant.js");
const ApiUrl = require("./baseApiUrl.js");
const BaseStringUtil = require("./baseStringUtil.js");
const RunDefine = require("./baseRunDefine.js");



// 操作 登录
const doToLoginStep2 = () => {
    let tv = text(MpesaKesPageTag.loginStep1PageTag2).findOnce();
    let tvBounds = tv.bounds();
    click(tvBounds.centerX(), tvBounds.centerY());
    return true;
}

// 操作 登录
const doToLoginStepPin = () => {
    let tv = text(MpesaKesPageTag.loginStep2PageTag4).findOnce();
    let tvBounds = tv.bounds();
    click(tvBounds.centerX(), tvBounds.centerY());
    return true;
}

// 操作 登录-pin
const doPinInput = () => {
    console.log(Constant.UI_SDK_VERSION + "doPinInput-开始操作登录-pin");

    let pinCodes = Constant.getPin();
    if (pinCodes.length >= 4) {
        let code1 = pinCodes.substring(0, 1);
        let code2 = pinCodes.substring(1, 2);
        let code3 = pinCodes.substring(2, 3);
        let code4 = pinCodes.substring(3, 4);

        let code1Index = -1;
        let code2Index = -1;
        let code3Index = -1;
        let code4Index = -1;

        let textList = className("TextView").find();
        for (let index = 0; index < textList.length; index++) {
            let tv = textList[index];
            let curText = tv.text().trim() || ""
            console.log(Constant.UI_SDK_VERSION + "doPinInput-当前-text: " + index + " +内容: " + curText);

            if (curText === code1) {
                code1Index = index;
            }
            if (curText === code2) {
                code2Index = index;
            }
            if (curText === code3) {
                code3Index = index;
            }
            if (curText === code4) {
                code4Index = index;
            }

            if ((code1Index >= 0) && (code2Index >= 0) && (code3Index >= 0) && (code4Index >= 0)) {
                break;
            }
        }

        if ((code1Index >= 0) && (code2Index >= 0) && (code3Index >= 0) && (code4Index >= 0)) {
            let code1TvBounds = textList[code1Index].bounds();
            let code2TvBounds = textList[code2Index].bounds();
            let code3TvBounds = textList[code3Index].bounds();
            let code4TvBounds = textList[code4Index].bounds();

            click(code1TvBounds.centerX(), code1TvBounds.centerY());
            sleep(1000);
            click(code2TvBounds.centerX(), code2TvBounds.centerY());
            sleep(1000);
            click(code3TvBounds.centerX(), code3TvBounds.centerY());
            sleep(1000);
            click(code4TvBounds.centerX(), code4TvBounds.centerY());
            sleep(1000);

            textList.length = 0;
            textList = null;

            return true;
        }

        // 重置为0
        textList.length = 0;
        textList = null;
        code1Index = -1;
        code2Index = -1;
        code3Index = -1;
        code4Index = -1;

        buttonList = className("Button").find();
        for (let index = 0; index < buttonList.length; index++) {
            let tv = buttonList[index];
            let curText = tv.text().trim() || ""
            console.log(Constant.UI_SDK_VERSION + "doPinInput-当前-button: " + index + " +内容: " + curText);

            if (curText === code1) {
                code1Index = index;
            }
            if (curText === code2) {
                code2Index = index;
            }
            if (curText === code3) {
                code3Index = index;
            }
            if (curText === code4) {
                code4Index = index;
            }

            if ((code1Index >= 0) && (code2Index >= 0) && (code3Index >= 0) && (code4Index >= 0)) {
                break;
            }
        }

        if ((code1Index >= 0) && (code2Index >= 0) && (code3Index >= 0) && (code4Index >= 0)) {
            let code1TvBounds = buttonList[code1Index].bounds();
            let code2TvBounds = buttonList[code2Index].bounds();
            let code3TvBounds = buttonList[code3Index].bounds();
            let code4TvBounds = buttonList[code4Index].bounds();

            click(code1TvBounds.centerX(), code1TvBounds.centerY());
            sleep(1000);
            click(code2TvBounds.centerX(), code2TvBounds.centerY());
            sleep(1000);
            click(code3TvBounds.centerX(), code3TvBounds.centerY());
            sleep(1000);
            click(code4TvBounds.centerX(), code4TvBounds.centerY());
            sleep(1000);

            buttonList.length = 0;
            buttonList = null;

            return true;
        }

        buttonList.length = 0;
        buttonList = null;
        return false;
    }

    return false;
}

// 操作 点击 send money tab 页
const doToSendMoneyPage = () => {
    // 点击 Send money
    console.log(Constant.UI_SDK_VERSION + "doOpenSendMoneyPage");
    // 点击左下角
    click(device.width / 8 * 3, device.height - 40);
    sleep(1000);
    return true;
}

// 操作 打开 send money-mobile select 页
const doToSendMoneyMobileSelectPage = () => {
    // 点击 Send money
    console.log(Constant.UI_SDK_VERSION + "doToSendMoneyMobileSelectPage");
    let tv = text(MpesaKesPageTag.sendMoneyPageTag4).findOnce();
    let tvBounds = tv.bounds();
    click(tvBounds.centerX(), tvBounds.centerY());
    return true;
}


// 操作 打开 send money-mobile input 页
const doToSendMoneyMobileInputPage = () => {
    // 点击 Send money
    console.log(Constant.UI_SDK_VERSION + "doToSendMoneyMobileInputPage");
    let tv = text(MpesaKesPageTag.sendMoneyMobileSelectPageTag2).findOnce();
    let tvBounds = tv.bounds();
    click(tvBounds.centerX(), tvBounds.centerY());
    return true;
}

// 操作 输入对方钱包号
const doSendMoneyInputTargetAccount = (targetAccount) => {
    // 输入对方钱包号
    console.log(Constant.UI_SDK_VERSION + "doSendMoneyInputTargetAccount-开始操作输入对方钱包号");

    let didInputAccount = false;
    let edit = className("EditText").findOnce();
    if (edit !== null) {
        edit.setText(targetAccount);
        didInputAccount = true;
        sleep(1000);
    }

    if (didInputAccount) {
        // 找出提交按键
        let textList = className("TextView").find();
        for (let index = 0; index < textList.length; index++) {
            let tv = textList[index];
            let curText = tv.text() || "";
            if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag3) !== -1) {
                let tvBounds = tv.bounds();
                click(tvBounds.centerX(), tvBounds.centerY());
                sleep(1000);

                textList.length = 0;
                textList = null;
                return true;
            }
        }
        textList.length = 0;
        textList = null;

        let buttonList = className("Button").find();
        for (let index = 0; index < buttonList.length; index++) {
            let tv = buttonList[index];
            let curText = tv.text() || "";
            if (curText.indexOf(MpesaKesPageTag.sendMoneyMobileInputPageTag3) !== -1) {
                let tvBounds = tv.bounds();
                click(tvBounds.centerX(), tvBounds.centerY());
                sleep(1000);

                buttonList.length = 0;
                buttonList = null;
                return true;
            }
        }

        buttonList.length = 0;
        buttonList = null;
    }
    return false;
}

// 操作 输入转账金额
const doSendMoneyInputTargetAmount = (targetAmount) => {
    // 输入对方钱包号
    console.log(Constant.UI_SDK_VERSION + "doSendMoneyInputTargetAmount-开始操作输入转账金额");

    let didInputAmount = false;
    let edit = className("EditText").findOnce();
    if (edit !== null) {
        edit.setText(targetAmount);
        didInputAmount = true;
        sleep(1000);
    }

    if (didInputAmount) {
        // 找出提交按键
        let textList = className("TextView").find();
        for (let index = 0; index < textList.length; index++) {
            let tv = textList[index];
            let curText = tv.text() || "";
            if (curText.indexOf(MpesaKesPageTag.sendMoneyAmountInputPageTag3) !== -1) {
                let tvBounds = tv.bounds();
                click(tvBounds.centerX(), tvBounds.centerY());
                sleep(1000);

                textList.length = 0;
                textList = null;
                return true;
            }
        }
        textList.length = 0;
        textList = null;

        let buttonList = className("Button").find();
        for (let index = 0; index < buttonList.length; index++) {
            let tv = buttonList[index];
            let curText = tv.text() || "";
            if (curText.indexOf(MpesaKesPageTag.sendMoneyAmountInputPageTag3) !== -1) {
                let tvBounds = tv.bounds();
                click(tvBounds.centerX(), tvBounds.centerY());
                sleep(1000);

                buttonList.length = 0;
                buttonList = null;
                return true;
            }
        }

        buttonList.length = 0;
        buttonList = null;
    }
    return false;
}

// 操作 点击确认转账
const doSendMoneyConfirm = () => {
    // 输入对方钱包号
    console.log(Constant.UI_SDK_VERSION + "doSendMoneyConfirm-开始操作确认转账");

    let buttonList = className("Button").find();
    for (let index = 0; index < buttonList.length; index++) {
        let tv = buttonList[index];
        let curText = tv.text().trim() || "";
        if (curText === MpesaKesPageTag.sendMoneyConfirmPageTag6) {
            let tvBounds = tv.bounds();
            click(tvBounds.centerX(), tvBounds.centerY());
            sleep(1000);

            buttonList.length = 0;
            buttonList = null;
            return true;
        }
    }
    buttonList.length = 0;
    buttonList = null;

    let textList = className("TextView").find();
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text().trim() || "";
        if (curText === MpesaKesPageTag.sendMoneyConfirmPageTag6) {
            let tvBounds = tv.bounds();
            click(tvBounds.centerX(), tvBounds.centerY());
            sleep(1000);

            textList.length = 0;
            textList = null;
            return true;
        }
    }
    textList.length = 0;
    textList = null;
    return false;
}

// 操作 点击输入转账密码
const doSendMoneyInputPassword = () => {
    console.log(Constant.UI_SDK_VERSION + "doSendMoneyInputPassword-开始操作转账-pin");

    let pinCodes = Constant.getPin();
    if (pinCodes.length >= 4) {
        let code1 = pinCodes.substring(0, 1);
        let code2 = pinCodes.substring(1, 2);
        let code3 = pinCodes.substring(2, 3);
        let code4 = pinCodes.substring(3, 4);

        let code1Index = -1;
        let code2Index = -1;
        let code3Index = -1;
        let code4Index = -1;

        let textList = className("TextView").find();
        for (let index = 0; index < textList.length; index++) {
            let tv = textList[index];
            let curText = tv.text().trim() || ""
            console.log(Constant.UI_SDK_VERSION + "doSendMoneyInputPassword-当前-text: " + index + " +内容: " + curText);

            if (curText === code1) {
                code1Index = index;
            }
            if (curText === code2) {
                code2Index = index;
            }
            if (curText === code3) {
                code3Index = index;
            }
            if (curText === code4) {
                code4Index = index;
            }

            if ((code1Index >= 0) && (code2Index >= 0) && (code3Index >= 0) && (code4Index >= 0)) {
                break;
            }
        }

        if ((code1Index >= 0) && (code2Index >= 0) && (code3Index >= 0) && (code4Index >= 0)) {
            let code1TvBounds = textList[code1Index].bounds();
            let code2TvBounds = textList[code2Index].bounds();
            let code3TvBounds = textList[code3Index].bounds();
            let code4TvBounds = textList[code4Index].bounds();

            click(code1TvBounds.centerX(), code1TvBounds.centerY());
            sleep(1000);
            click(code2TvBounds.centerX(), code2TvBounds.centerY());
            sleep(1000);
            click(code3TvBounds.centerX(), code3TvBounds.centerY());
            sleep(1000);
            click(code4TvBounds.centerX(), code4TvBounds.centerY());
            sleep(1000);

            textList.length = 0;
            textList = null;

            return true;
        }

        // 重置为0
        textList.length = 0;
        textList = null;
        code1Index = -1;
        code2Index = -1;
        code3Index = -1;
        code4Index = -1;

        buttonList = className("Button").find();
        for (let index = 0; index < buttonList.length; index++) {
            let tv = buttonList[index];
            let curText = tv.text().trim() || ""
            console.log(Constant.UI_SDK_VERSION + "doSendMoneyInputPassword-当前-button: " + index + " +内容: " + curText);

            if (curText === code1) {
                code1Index = index;
            }
            if (curText === code2) {
                code2Index = index;
            }
            if (curText === code3) {
                code3Index = index;
            }
            if (curText === code4) {
                code4Index = index;
            }

            if ((code1Index >= 0) && (code2Index >= 0) && (code3Index >= 0) && (code4Index >= 0)) {
                break;
            }
        }

        if ((code1Index >= 0) && (code2Index >= 0) && (code3Index >= 0) && (code4Index >= 0)) {
            let code1TvBounds = buttonList[code1Index].bounds();
            let code2TvBounds = buttonList[code2Index].bounds();
            let code3TvBounds = buttonList[code3Index].bounds();
            let code4TvBounds = buttonList[code4Index].bounds();

            click(code1TvBounds.centerX(), code1TvBounds.centerY());
            sleep(1000);
            click(code2TvBounds.centerX(), code2TvBounds.centerY());
            sleep(1000);
            click(code3TvBounds.centerX(), code3TvBounds.centerY());
            sleep(1000);
            click(code4TvBounds.centerX(), code4TvBounds.centerY());
            sleep(1000);

            buttonList.length = 0;
            buttonList = null;

            return true;
        }

        buttonList.length = 0;
        buttonList = null;
        return false;
    }

    return false;
}

// 操作 点击 Done 结束返回
const doSendMoneySuccessDone = () => {
    // 点击 back
    console.log(Constant.UI_SDK_VERSION + "doSendMoneySuccessDone-开始操作点击 Done");
    // click(MpesaKesPageTag.sendMoneySuccessPageDoneTag1);
    // sleep(500);
    // click(MpesaKesPageTag.sendMoneySuccessPageDoneTag1);

    let tv = text(MpesaKesPageTag.sendMoneySuccessPageDoneTag1).findOnce();
    let tvBounds = tv.bounds();
    click(tvBounds.centerX(), tvBounds.centerY());
    sleep(1000)
    click(device.width / 8 * 1, device.height - 40);
    sleep(1000);
    return true;
}

// 操作 点击 Done 结束返回
const doSendMoneyFailDone = () => {
    // 点击 back
    console.log(Constant.UI_SDK_VERSION + "doSendMoneyFailDone-开始操作点击 Done");
    // click(MpesaKesPageTag.sendMoneySuccessPageFailTag1);
    // sleep(500);
    // click(MpesaKesPageTag.sendMoneySuccessPageFailTag1);
    // sleep(1000)

    let tv = text(MpesaKesPageTag.sendMoneySuccessPageFailTag1).findOnce();
    let tvBounds = tv.bounds();
    click(tvBounds.centerX(), tvBounds.centerY());
    sleep(1000)
    click(device.width / 8 * 1, device.height - 40);
    sleep(1000);
    return true;
}

// 操作 点击 Transactions
const doToBillListPage = () => {
    // 点击 Transactions
    console.log(Constant.UI_SDK_VERSION + "doClickTransacitons-开始操作点击 Transactions");
    let tv = text(MpesaKesPageTag.homePageTag4).findOnce();
    let tvBounds = tv.bounds();
    click(tvBounds.centerX(), tvBounds.centerY());
    sleep(1000);
    return true;
}

// ==================== 流水操作-start ====================
// 上报缓存记录
const mBillIdsCached = [];

// 首屏记录
const mBillFirstScreenCached = [];

// 测试
const testArray1 = [];

// 测试
const doTestArray = (index) => {

    let bill1 = [{
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 07, 10:56',
        shortAmount: '-10F'
    },
    {
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 07, 10:45',
        shortAmount: '-10F'
    },
    {
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 07, 10:27',
        shortAmount: '-10F'
    },
    {
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 07, 10:22',
        shortAmount: '-10F'
    },
    {
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 06, 18:45',
        shortAmount: '-15F'
    },
    {
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 06, 18:24',
        shortAmount: '-15F'
    }];

    let bill2 = [{
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 07, 10:45',
        shortAmount: '-10F'
    },
    {
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 07, 10:27',
        shortAmount: '-10F'
    },
    {
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 07, 10:22',
        shortAmount: '-10F'
    },
    {
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 06, 18:45',
        shortAmount: '-15F'
    },
    {
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 06, 18:24',
        shortAmount: '-15F'
    },
    {
        shortType: 'Sent to Qin L 07 10 00 24 59',
        shortDate: 'Mar 06, 18:16',
        shortAmount: '-15F'
    }];

    let chagedStatus = doIsBillsListChanged(bill1, bill2);
    console.log(chagedStatus);

    // let list = [];
    // for (let i = 0; i < index; i++) {
    //     let content = (i + 1) + "";
    //     let item = {};
    //     item.shortType = content;
    //     item.shortDate = content;
    //     item.shortAmount = content;
    //     list.push(item);
    // }
    // doDeepCloneShortBills(testArray1, list);

    // console.log("======")
    // console.log(testArray1);
    // console.log("======")
}

/**
 *  深拷贝首页短流水记录
 */
const doDeepCloneShortBills = (arr1, arr2) => {
    if (!arr2) {
        return;
    }

    if (!arr1) {
        arr1 = [];
        return;
    }

    // 重置
    arr1.length = 0;
    // 深拷贝
    for (let di = 0; di < arr2.length; di++) {
        let diItem = arr2[di];
        let cloneItem = {};
        cloneItem.shortType = diItem.shortType;
        cloneItem.shortDate = diItem.shortDate;
        cloneItem.shortAmount = diItem.shortAmount;
        cloneItem.shortMobile = diItem.shortMobile;
        cloneItem.shortReference = diItem.shortReference || "";
        arr1.push(cloneItem);
    }
};

/**
 *  判断两个bill item是否相同
 */
const doIsSameBillItems = (billItem1, billItem2) => {
    if (!billItem1) {
        return false;
    }
    if (!billItem2) {
        return false;
    }

    // 判断是否发生变化
    let isAmountChanged = (billItem1.shortAmount !== billItem2.shortAmount);
    let isDateChanged = (billItem1.shortDate !== billItem2.shortDate);
    let isTypeChanged = (billItem1.shortType !== billItem2.shortType);
    let isMobileChanged = (billItem1.shortMobile !== billItem2.shortMobile);
    if (isAmountChanged || isDateChanged || isTypeChanged || isMobileChanged) {
        return false;
    }

    // 默认相同
    return true;
}

/**
* 判断两屏数据是否发生变动
* @param bill1 目标数组
* @param bill2 旧数组，拿来作比较用
*/
const doIsBillsListChanged = (bill1, bill2) => {
    // 改变状态详情
    let changedStatus = {
        isBillsChanged: false,
        isNeedCheckAll: false,
        recheckBills: []
    };
    if ((!bill1) && (bill2)) {
        changedStatus.isBillsChanged = false;
        changedStatus.isNeedCheckAll = false;
        changedStatus.recheckBills.length = 0;
        return changedStatus;
    }
    if ((bill1) && (!bill2)) {
        changedStatus.isBillsChanged = true;
        changedStatus.isNeedCheckAll = true;
        changedStatus.recheckBills.length = 0;

        // 复制
        for (let i = 0; i < bill1.length; i++) {
            let bill1ItemNext = bill1[i];
            let changeItemNext = {};
            changeItemNext.shortAmount = bill1ItemNext.shortAmount;
            changeItemNext.shortDate = bill1ItemNext.shortDate;
            changeItemNext.shortType = bill1ItemNext.shortType;
            changeItemNext.shortMobile = bill1ItemNext.shortMobile;
            changeItemNext.shortReference = bill1ItemNext.shortReference || "";
            changedStatus.recheckBills.push(changeItemNext);
        }

        return changedStatus;
    }
    if ((bill1.length > 0) && (bill2.length == 0)) {
        changedStatus.isBillsChanged = true;
        changedStatus.isNeedCheckAll = true;
        changedStatus.recheckBills.length = 0;

        // 复制
        for (let i = 0; i < bill1.length; i++) {
            let bill1ItemNext = bill1[i];
            let changeItemNext = {};
            changeItemNext.shortAmount = bill1ItemNext.shortAmount;
            changeItemNext.shortDate = bill1ItemNext.shortDate;
            changeItemNext.shortType = bill1ItemNext.shortType;
            changeItemNext.shortMobile = bill1ItemNext.shortMobile;
            changeItemNext.shortReference = bill1ItemNext.shortReference || "";
            changedStatus.recheckBills.push(changeItemNext);
        }

        return changedStatus;
    }
    if ((bill1.length == 0) && (bill2.length > 0)) {
        changedStatus.isBillsChanged = false;
        changedStatus.isNeedCheckAll = false;
        changedStatus.recheckBills.length = 0;
        return changedStatus;
    }

    // 长度 <
    if (bill1.length < bill2.length) {
        changedStatus.isBillsChanged = false;
        changedStatus.isNeedCheckAll = false;
        changedStatus.recheckBills.length = 0;

        // 循环遍历
        // 对比第1个不同的无素
        let bill2ItemNext = bill2[0];
        for (let rIndex = 0; rIndex < bill1.length; rIndex++) {
            let bill1ItemNext = bill1[rIndex];
            let isSameBillItem = doIsSameBillItems(bill1ItemNext, bill2ItemNext);
            console.log("======= " + rIndex + " < -isSameBillItem:" + isSameBillItem);

            // 第n个发生变化
            if (!isSameBillItem) {
                changedStatus.isBillsChanged = true;

                let changeItemNext = {};
                changeItemNext.shortAmount = bill1ItemNext.shortAmount;
                changeItemNext.shortDate = bill1ItemNext.shortDate;
                changeItemNext.shortType = bill1ItemNext.shortType;
                changeItemNext.shortMobile = bill1ItemNext.shortMobile;
                changeItemNext.shortReference = bill1ItemNext.shortReference || "";
                changedStatus.recheckBills.push(changeItemNext);
            } else {
                break;
            }
        }

        return changedStatus;
    }

    // 长度 =
    if (bill1.length === bill2.length) {
        changedStatus.isBillsChanged = false;
        changedStatus.isNeedCheckAll = false;
        changedStatus.recheckBills.length = 0;

        // 循环遍历
        // 对比第1个不同的无素
        let bill2ItemNext = bill2[0];
        for (let rIndex = 0; rIndex < bill1.length; rIndex++) {
            let bill1ItemNext = bill1[rIndex];
            let isSameBillItem = doIsSameBillItems(bill1ItemNext, bill2ItemNext);
            console.log("======= " + rIndex + " < -isSameBillItem:" + isSameBillItem);

            // 第n个发生变化
            if (!isSameBillItem) {
                changedStatus.isBillsChanged = true;

                let changeItemNext = {};
                changeItemNext.shortAmount = bill1ItemNext.shortAmount;
                changeItemNext.shortDate = bill1ItemNext.shortDate;
                changeItemNext.shortType = bill1ItemNext.shortType;
                changeItemNext.shortMobile = bill1ItemNext.shortMobile;
                changeItemNext.shortReference = bill1ItemNext.shortReference || "";
                changedStatus.recheckBills.push(changeItemNext);
            } else {
                break;
            }
        }
        return changedStatus;
    }

    // 长度 >
    if (bill1.length > bill2.length) {
        changedStatus.isBillsChanged = true;
        changedStatus.isNeedCheckAll = false;
        changedStatus.recheckBills.length = 0;

        // 循环遍历
        // 对比第1个不同的无素
        let bill2ItemNext = bill2[0];
        for (let rIndex = 0; rIndex < bill1.length; rIndex++) {
            let bill1ItemNext = bill1[rIndex];
            let isSameBillItem = doIsSameBillItems(bill1ItemNext, bill2ItemNext);
            console.log("======= " + rIndex + " < -isSameBillItem:" + isSameBillItem);

            // 第n个发生变化
            if (!isSameBillItem) {
                changedStatus.isBillsChanged = true;

                let changeItemNext = {};
                changeItemNext.shortAmount = bill1ItemNext.shortAmount;
                changeItemNext.shortDate = bill1ItemNext.shortDate;
                changeItemNext.shortType = bill1ItemNext.shortType;
                changeItemNext.shortMobile = bill1ItemNext.shortMobile;
                changeItemNext.shortReference = bill1ItemNext.shortReference || "";
                changedStatus.recheckBills.push(changeItemNext);
            } else {
                break;
            }
        }
        return changedStatus;
    }

    changedStatus.isBillsChanged = false;
    changedStatus.isNeedCheckAll = false;
    changedStatus.recheckBills.length = 0;
    return changedStatus;
};

// 新增流水详情缓存
const doAddBillRecord = (billItem) => {
    if (billItem) {
        let transactionID = billItem.billID;
        if (doIsBillRecordExist(transactionID)) {
            return false;
        } else {
            mBillIdsCached.push(billItem);
            return true;
        }
    }
    return false;
};

// 查询交易流水是否存在缓存
const doIsBillRecordExist = (transactionID) => {
    if (!transactionID) {
        return false;
    }

    for (let i = 0; i < mBillIdsCached.length; i++) {
        let item = mBillIdsCached[i];
        if (item.billID.startsWith(transactionID)) {
            console.log(Constant.UI_SDK_VERSION + "doIsBillRecordExist-交易id已存在, 不作处理-" + transactionID);
            return true;
        }
    }
    console.log(Constant.UI_SDK_VERSION + "doIsBillRecordExist-交易id不存在, 增加到缓存-" + transactionID);

    return false;
};

/** 查询当前屏的所有数据 */
const doGetAllBillsForFirstScreen = () => {
    // 读取当前列表
    let textList = className("TextView").find();
    let startIndex = 0;
    while (startIndex < textList.length) {
        let curTv = textList[startIndex];
        let curText = curTv.text().trim() || "";
        console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForFirstScreen-当前: " + startIndex + ", 内容: " + curText);

        // 判断是否为有效的记录
        let isRecordTagAmount = BaseStringUtil.isKenyaAmountFormat(curText);
        console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForFirstScreen-当前: " + startIndex + ", isRecordTagAmount: " + isRecordTagAmount);

        if (isRecordTagAmount) {
            // 这是行开头, 再判断是否为完整的行记录
            let nameIndex = (startIndex - 1);
            let mobileIndex = -1;
            let dateIndex = -1;

            let nameValue = textList[nameIndex].text().trim() || "";
            let mobileValue = "";
            let dateValue = "";

            // 找到号码 
            for (let findIndex = (startIndex + 1); findIndex < (startIndex + 4); findIndex++) {
                let findTv = textList[findIndex];
                let findText = findTv.text().trim() || "";
                let isMobile = BaseStringUtil.isPhoneEncrptFormat(findText);
                if (isMobile) {
                    mobileIndex = findIndex;
                    mobileValue = findText;
                    break;
                }
            }

            // 找到时间
            for (let findIndex = (startIndex + 1); findIndex < (startIndex + 4); findIndex++) {
                let findTv = textList[findIndex];
                let findText = findTv.text().trim() || "";
                let isDate = BaseStringUtil.isDateHHMMFormat(findText);
                if (isDate) {
                    dateIndex = findIndex;
                    dateValue = findText;
                    break;
                }
            }

            // 判断是否可以点击
            let amountTvBounds = curTv.bounds();
            let canClick = (device.height - amountTvBounds.centerY() >= 0);
            console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForFirstScreen-号码: " + curText + ", 金额centerY: " + amountTvBounds.centerY() + ", canClick: " + canClick);

            if (!canClick) {
                // 最后一行的Y坐标
                startIndex = textList.length;

                // 不是有效的行数据, 需要往下滑
                console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForFirstScreen-已经读完当前屏幕的有效数据, 跳出循环,  最后一行的centerY坐标: " + amountTvBounds.centerY());
                continue;
            }

            // 添加缓存
            let rowData = {};
            rowData.mobile = mobileValue;
            rowData.name = nameValue;
            rowData.amount = curText;
            rowData.date = dateValue;

            // 点击
            click(amountTvBounds.centerX(), amountTvBounds.centerY());
            sleep(1000);

            // 读取流水详情
            doGetBillDetails(rowData);
            sleep(1000);

            console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForFirstScreen-读完-准备下一个游标=====");
            // 更新起始位置
            if (dateIndex >= startIndex) {
                startIndex = (dateIndex + 1);
            } else {
                startIndex += 1;
            }
            // sleep(1 * 1000);
            continue;
        }
        startIndex += 1;
    }

    textList.length = 0;
    textList = null;

    // 打印
    console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForCurrentScreen-共有效数据: " + mBillIdsCached.length);
    console.log(mBillIdsCached);

    sleep(500);
    return true;
};

// 查询当前屏的所有数据
const doGetAllBillsForCurrentScreen = (isFirstScreen) => {
    // 最多遍历5次, 测试来看足够了
    let xPullStart = (device.width * 0.8);
    let yPullStart = 200;
    let yPullEnd = (device.height - 60);

    // 数据列表
    let dataList = [];

    // 读取当前列表
    let textList = className("TextView").find();
    let startIndex = 0;
    while (startIndex < textList.length) {
        let curTv = textList[startIndex];
        let curText = curTv.text() || "";

        // 判断是否为有效的记录
        let isRecordTagMobile = BaseStringUtil.isDigitAndBlankSpaceOnly(curText);
        let isShopTag = curText.startsWith(MpesaKesPageTag.transactionListItemTagShop);
        console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForCurrentScreen-当前: " + startIndex + ", 内容: " + curText + ", isMobile: " + isRecordTagMobile + ", isShop: " + isShopTag);

        if (isRecordTagMobile || isShopTag) {
            // 这是行开头, 再判断是否为完整的行记录
            let amountIndex = (startIndex + 1);
            let typeIndex = (startIndex + 2);
            let dateIndex = (startIndex + 3);

            if (dateIndex < textList.length) {
                // 只有包含金额与日期的数据, 才是完整的行记录数据
                let amountTv = textList[amountIndex];
                let typeTv = textList[typeIndex];
                let dateTv = textList[dateIndex];

                let amountText = amountTv.text() || "";
                let typeText = typeTv.text() || "";
                let dateText = dateTv.text() || "";

                // 判断是否可以点击
                let canClick = (device.height - dateTv.bounds().bottom >= 0);
                console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForCurrentScreen-号码: " + curText + ", 号码top: " + curTv.bounds().top + ", 日期bottom: " + dateTv.bounds().bottom + ", canClick: " + canClick);

                if (!canClick) {
                    // 最后一行的Y坐标
                    startIndex = textList.length;

                    // 不是有效的行数据, 需要往下滑
                    console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForCurrentScreen-已经读完当前屏幕的有效数据, 跳出循环,  最后一行的Y坐标: " + dateTv.bounds().bottom);
                    continue;
                }

                if (!isFirstScreen) {
                    if (curTv.bounds().top < yPullStart) {
                        console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForCurrentScreen-非首屏-准备下一个游标=====" + curTv.bounds().top + "-" + yPullStart);
                        // 更新起始位置
                        startIndex = (dateIndex + 1);
                        // sleep(1 * 1000);
                        continue;
                    }
                }

                // 添加缓存
                let rowData = {};
                rowData.shortMobile = curText;
                rowData.shortType = typeText;
                rowData.shortDate = dateText;
                rowData.shortAmount = amountText;
                rowData.top = amountTv.bounds().top;
                rowData.bottom = dateTv.bounds().bottom;
                rowData.centerX = amountTv.bounds().centerX();
                rowData.centerY = amountTv.bounds().centerY();
                dataList.push(rowData);

                console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForCurrentScreen-读完-准备下一个游标=====");
                // 更新起始位置
                startIndex = (dateIndex + 1);
                // sleep(1 * 1000);
                continue;

            }
        }
        startIndex += 1;
    }

    textList.length = 0;
    textList = null;

    // 打印
    console.log(Constant.UI_SDK_VERSION + "doGetAllBillsForCurrentScreen-共有效数据: " + dataList.length);
    console.log(dataList);
    // for (let i = 0; i < dataList.length; i++) {
    //     let item = dataList[i];
    //     console.log(Constant.UI_SDK_VERSION + "doGetBillsForCurrentScreen-" + i + ": " + item.shortType);
    // }

    return dataList;
};

// 查询当前屏的数据
const doGetBillsForCurrentScreen = (isFirstScreen) => {

    // 最多遍历5次, 测试来看足够了
    let xPullStart = (device.width * 0.8);
    let yPullStart = 200;
    let yPullEnd = (device.height - 60);

    // 数据列表
    let dataList = [];

    // 读取当前列表
    let textList = className("TextView").find();
    let startIndex = 0;
    while (startIndex < textList.length) {
        let curTv = textList[startIndex];
        let curText = curTv.text() || "";

        // 判断是否为有效的记录
        let isRecordTagMobile = BaseStringUtil.isDigitAndBlankSpaceOnly(curText);
        let isShopTag = curText.startsWith(MpesaKesPageTag.transactionListItemTagShop);
        console.log(Constant.UI_SDK_VERSION + "doGetBillsForCurrentScreen-当前: " + startIndex + ", 内容: " + curText + ", isMobile: " + isRecordTagMobile + ", isShop: " + isShopTag);

        if (isRecordTagMobile || isShopTag) {
            // 这是行开头, 再判断是否为完整的行记录
            let amountIndex = (startIndex + 1);
            let typeIndex = (startIndex + 2);
            let dateIndex = (startIndex + 3);

            if (dateIndex < textList.length) {
                // 只有包含金额与日期的数据, 才是完整的行记录数据
                let amountTv = textList[amountIndex];
                let typeTv = textList[typeIndex];
                let dateTv = textList[dateIndex];

                let amountText = amountTv.text() || "";
                let typeText = typeTv.text() || "";
                let dateText = dateTv.text() || "";

                // 判断是否可以点击
                let canClick = (device.height - dateTv.bounds().bottom >= 323);
                console.log(Constant.UI_SDK_VERSION + "doGetBillsForCurrentScreen-号码: " + curText + ", 号码top: " + curTv.bounds().top + ", 日期bottom: " + dateTv.bounds().bottom + ", canClick: " + canClick);

                if (!canClick) {
                    // 最后一行的Y坐标
                    lastRowY = dateTv.bounds().bottom - 0;
                    startIndex = textList.length;

                    // 不是有效的行数据, 需要往下滑
                    console.log(Constant.UI_SDK_VERSION + "doGetBillsForCurrentScreen-已经读完当前屏幕的有效数据, 跳出循环,  最后一行的Y坐标: " + lastRowY);
                    continue;
                }

                if (!isFirstScreen) {
                    if (curTv.bounds().top < yPullStart) {
                        console.log(Constant.UI_SDK_VERSION + "doGetBillsForCurrentScreen-非首屏-准备下一个游标=====" + curTv.bounds().top + "-" + yPullStart);
                        // 更新起始位置
                        startIndex = (dateIndex + 1);
                        // sleep(1 * 1000);
                        continue;
                    }
                }

                // 添加缓存
                let rowData = {};
                rowData.shortMobile = curText;
                rowData.shortType = typeText;
                rowData.shortDate = dateText;
                rowData.shortAmount = amountText;
                rowData.top = amountTv.bounds().top;
                rowData.bottom = dateTv.bounds().bottom;
                rowData.centerX = amountTv.bounds().centerX();
                rowData.centerY = amountTv.bounds().centerY();
                dataList.push(rowData);

                console.log(Constant.UI_SDK_VERSION + "doGetBillsForCurrentScreen-读完-准备下一个游标=====");
                // 更新起始位置
                startIndex = (dateIndex + 1);
                // sleep(1 * 1000);
                continue;

            }
        }
        startIndex += 1;
    }

    textList.length = 0;
    textList = null;

    // 打印
    console.log(Constant.UI_SDK_VERSION + "doGetBillsForCurrentScreen-共有效数据: " + dataList.length);
    console.log(dataList);
    // for (let i = 0; i < dataList.length; i++) {
    //     let item = dataList[i];
    //     console.log(Constant.UI_SDK_VERSION + "doGetBillsForCurrentScreen-" + i + ": " + item.shortType);
    // }

    return dataList;
};

// 查询当前行展开的数据
const doGetBillDetailForRowExtend = () => {
    // 读取当前列表
    let textList = className("TextView").find();
    let startIndex = 0;
    while (startIndex < textList.length) {
        let curTv = textList[startIndex];
        let curText = curTv.text() || "";

        // 判断是否为有效的记录
        let isRecordTagMobile = BaseStringUtil.isDigitAndBlankSpaceOnly(curText);
        let isShopTag = curText.startsWith(MpesaKesPageTag.transactionListItemTagShop);
        console.log(Constant.UI_SDK_VERSION + "doGetBillDetailForRowExtend-当前: " + startIndex + ", 内容: " + curText + ", isMobile: " + isRecordTagMobile + ", isShop: " + isShopTag);

        if (isRecordTagMobile || isShopTag) {
            // 这是行开头, 再判断是否为完整的行记录
            let amountIndex = (startIndex + 1);
            let typeIndex = (startIndex + 2);
            let dateIndex = (startIndex + 3);

            if (dateIndex < textList.length) {
                // 只有包含金额与日期的数据, 才是完整的行记录数据
                let amountTv = textList[amountIndex];
                let typeTv = textList[typeIndex];
                let dateTv = textList[dateIndex];

                let amountText = amountTv.text() || "";
                let typeText = typeTv.text() || "";
                let dateText = dateTv.text() || "";

                // 判断是否为展开行
                let mobileIndex = (startIndex + 4);
                let mobileValueIndex = -1;
                let referenceIndex = -1;
                let referenceValueIndex = -1;

                let isFoundRowExtendTagMobile = false;
                let isFoundRowExtendTagReference = false;

                if (mobileIndex < textList.length) {
                    let mobileTv = textList[mobileIndex];
                    let mobileText = mobileTv.text() || "";
                    // 判断是否为 号码 行
                    if (mobileText.indexOf(MpesaKesPageTag.transactionListItemExtendTagMobile) !== -1) {
                        isFoundRowExtendTagMobile = true;
                        mobileValueIndex = (mobileIndex + 1); // 可能没有值
                    }
                }

                // 寻找 mobile
                if ((mobileValueIndex >= 0) && (mobileValueIndex < textList.length)) {
                    let mobileValueTv = textList[mobileValueIndex];
                    let mobileValueText = mobileValueTv.text() || "";
                    console.log(Constant.UI_SDK_VERSION + "doGetBillDetailForRowExtend-mobileValueText: " + mobileValueText);
                    if ((mobileValueText.length > 0) && BaseStringUtil.isDigitAndBlankSpaceOnly(mobileValueText)) {
                        mobileValueIndex = (mobileIndex + 1);
                    } else {
                        mobileValueIndex = -1;
                    }
                }
                console.log(Constant.UI_SDK_VERSION + "doGetBillDetailForRowExtend-mobileValueIndex: " + mobileValueIndex);

                // 寻找 reference
                for (let refIndex = mobileIndex; refIndex < (mobileIndex + 5); refIndex++) {
                    let referenceTv = textList[refIndex];
                    let referenceText = referenceTv.text() || "";
                    if (referenceText.indexOf(MpesaKesPageTag.transactionListItemExtendTagReference) !== -1) {
                        isFoundRowExtendTagReference = true;
                        referenceIndex = refIndex;
                        referenceValueIndex = (referenceIndex + 1);
                    }
                }
                console.log(Constant.UI_SDK_VERSION + "doGetBillDetailForRowExtend-referenceIndex: " + referenceIndex);

                if ((referenceIndex >= 0) && (referenceIndex < textList.length)) {
                    let referenceTv = textList[referenceIndex];
                    let referenceText = referenceTv.text() || "";
                    if (referenceText.indexOf(MpesaKesPageTag.transactionListItemExtendTagReference) !== -1) {
                        isFoundRowExtendTagReference = true;
                        referenceValueIndex = (referenceIndex + 1);
                    }
                }
                console.log(Constant.UI_SDK_VERSION + "doGetBillDetailForRowExtend-referenceValueIndex: " + referenceValueIndex);

                // 确认为展开行，直接返回
                if (isFoundRowExtendTagMobile && isFoundRowExtendTagReference) {
                    // reference值
                    let referenceValueTv = textList[referenceValueIndex];
                    let referenceValueText = referenceValueTv.text() || "";

                    // 添加缓存
                    let rowData = {};
                    rowData.shortMobile = curText;
                    rowData.shortType = typeText;
                    rowData.shortDate = dateText;
                    rowData.shortAmount = amountText;
                    rowData.shortReference = referenceValueText;
                    console.log(Constant.UI_SDK_VERSION + "doGetBillDetailForRowExtend-有效展示行详情===");
                    console.log(rowData);

                    // 再次点击 关闭
                    click(referenceValueText);
                    sleep(1000);
                    return rowData;
                }

                console.log(Constant.UI_SDK_VERSION + "doGetBillDetailForRowExtend-准备下一个游标=====");
                // 更新起始位置
                startIndex = (dateIndex + 1);
                // sleep(1 * 1000);
                continue;

            }
        }

        startIndex += 1;
    }

    textList.length = 0;
    textList = null;

    return null;
};

// 处理每个版页的数据需求
const doScanBillsForEachScreen = () => {
    // 是否为一个周期
    let isOneLoop = true;

    // 控制缓存不超过20条
    let needDelCount = (mBillIdsCached.length - 20);
    if (needDelCount > 0) {
        mBillIdsCached.splice(0, needDelCount);
    }

    // 是否滑动到底部
    let hadSwipeToBottom = false;

    // 最多遍历5次, 测试来看足够了
    let xPullStart = (device.width * 0.8);
    let yPullStart = 200;
    let yPullEnd = (device.height - 60);

    // 滑动到顶部
    swipe(xPullStart, yPullStart, xPullStart, yPullEnd, 1000);
    sleep(2 * 1000);

    for (let pageSize = 0; pageSize < 20; pageSize++) {
        console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-pageSize:" + pageSize + "==========");

        // 先查出当前屏的有效数据
        let curScreenBillList = doGetBillsForCurrentScreen(pageSize === 0);

        // 判断首屏数据有没有变化
        if (pageSize === 0) {
            console.log("======== " + pageSize + "doScanBillsForEachScreen-curScreenBillList-" + curScreenBillList.length);
            console.log(curScreenBillList);
            console.log("======== " + pageSize + "doScanBillsForEachScreen-mBillFirstScreenCached-" + mBillFirstScreenCached.length);
            console.log(mBillFirstScreenCached);

            // 如果存在缓存，则判断
            if (mBillFirstScreenCached.length > 0) {
                let chagedStatus = doIsBillsListChanged(curScreenBillList, mBillFirstScreenCached);
                let isChagedForLastBillList = chagedStatus.isBillsChanged;
                console.log("======== " + pageSize + "doScanBillsForEachScreen-chagedStatus-isChanged-" + isChagedForLastBillList);
                console.log(chagedStatus.recheckBills);

                if (isChagedForLastBillList) {
                    // 点击 
                    for (let changedIndex = 0; changedIndex < chagedStatus.recheckBills.length; changedIndex++) {
                        let item = chagedStatus.recheckBills[changedIndex];
                        console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-click-changed:" + item.centerX + "," + item.centerY);
                        // 点击查看reference
                        click(item.centerX, item.centerY);
                        sleep(1000);

                        // 判断行是否已展开
                        let rowData = doGetBillDetailForRowExtend();
                        if (rowData) {
                            doAddBillRecord(rowData);
                        }
                        console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-click-changed-所有流水数据抓取结束===");
                        sleep(500);
                    }

                    console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-已处理完变化的数据, 退出循环");
                    return true;
                } else {
                    console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-当前屏数据与上一屏数据没变化, 不作处理");
                    // 上报当前这版的数据
                    // ...
                    return true;
                }
            }
        }

        // 缓存首屏数据
        if (pageSize === 0) {
            console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-是首屏数据, 先保存");
            doDeepCloneShortBills(mBillFirstScreenCached, curScreenBillList);
        }

        for (let billIndex = 0; billIndex < curScreenBillList.length; billIndex++) {
            let item = curScreenBillList[billIndex];
            console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-click:" + item.centerX + "," + item.centerY);
            // 点击查看reference
            click(item.centerX, item.centerY);
            sleep(1000);

            // 判断行是否已展开
            let rowData = doGetBillDetailForRowExtend();
            if (rowData) {
                doAddBillRecord(rowData);
            }
            sleep(1000);
        }

        // 如果到底了，直接返回
        // if (hadSwipeToBottom) {
        //     console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-所有流水数据抓取结束===");
        //     return;
        // }

        // 拿到最后一个记录，取bottom为滑动起点，往上滑一屏，yEnd = 200
        if (curScreenBillList.length > 0) {
            let item = curScreenBillList[curScreenBillList.length - 1];
            console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-yStart: " + item.bottom + ", yEnd: " + yPullStart);
            swipe(xPullStart, item.bottom, xPullStart, yPullStart, 2000);
            sleep(3000);
        }

        // 判断是否到底
        let nextScreenBillList = doGetBillsForCurrentScreen(pageSize === 0);
        let nextChagedStatus = doIsBillsListChanged(nextScreenBillList, curScreenBillList);
        let lastNotRecordStartIndex = nextScreenBillList.length;
        if (nextChagedStatus.isBillsChanged === false) {
            // 证明到底了，读取当前屏所有数据
            // 清空缓存
            nextScreenBillList.length = 0;
            nextScreenBillList = null;

            nextChagedStatus.recheckBills.length = 0;
            nextChagedStatus = null;

            // 设置到底标志
            hadSwipeToBottom = true;

            // 记录最后未记录的行
            let lastScreenBillList = doGetAllBillsForCurrentScreen(pageSize === 0);
            // 点击 
            for (let lastIndex = lastNotRecordStartIndex; lastIndex < lastScreenBillList.length; lastIndex++) {
                let item = lastScreenBillList[lastIndex];
                console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-click-last:" + item.centerX + "," + item.centerY);
                // 点击查看reference
                click(item.centerX, item.centerY);
                sleep(1000);

                // 判断行是否已展开
                let rowData = doGetBillDetailForRowExtend();
                if (rowData) {
                    doAddBillRecord(rowData);
                }
                console.log(Constant.UI_SDK_VERSION + "doScanBillsForEachScreen-click-last-所有流水数据抓取结束===");
                sleep(1000);
                return true;
            }
        }

        sleep(10000);
    }

    return true;
};

// 查看流水详情页
const doGetBillDetails = (shortBillItem) => {
    // 详情内容
    let billDetail = {};
    billDetail.amount = shortBillItem.amount || "";
    billDetail.date = shortBillItem.date || "";
    billDetail.mobile = shortBillItem.mobile || "";
    billDetail.name = shortBillItem.name || "";
    billDetail.billID = shortBillItem.billID || "";
    billDetail.fee = shortBillItem.fee || "";

    // 读取当前列表
    let textList = className("TextView").find();
    for (let index = 0; index < textList.length; index++) {
        let curTv = textList[index];
        let curText = curTv.text().trim() || ""
        console.log(Constant.UI_SDK_VERSION + "doGetBillDetails-当前: " + index + ", 内容: " + curText);

        // 找到日期
        if (BaseStringUtil.isDateHHMMFormat(curText)) {
            billDetail.date = curText;
        }

        // 找到金额
        if (BaseStringUtil.isKenyaAmountFormat(curText)) {
            billDetail.amount = curText;
        }

        // 找到fee
        if (BaseStringUtil.isKenyaBillFeeFormat(curText)) {
            if (curText.indexOf(MpesaKesPageTag.billDetailPageTag1) !== -1) {
                billDetail.fee = curText;
            } else {
                let feeIndex = (index + 1);
                if (feeIndex < textList.length) {
                    let feeTv = textList[feeIndex];
                    let feeText = feeTv.text().trim() || ""
                    if (feeText.indexOf(MpesaKesPageTag.billDetailPageTag1) !== -1) {
                        billDetail.fee = feeText;
                    }
                }
            }
        }

        // 找到id
        if (BaseStringUtil.isKenyaBillIDFormat(curText)) {
            billDetail.billID = curText;
        }
    }

    textList.length = 0;
    textList = null;

    // 增加缓存
    let addSuccess = doAddBillRecord(billDetail);
    if (addSuccess) {
        // 在这里上报后台
        // ...
        // console.log(billDetail);
    } else {
        // console.log(Constant.UI_SDK_VERSION + "doGetBillDetails-交易id已存在, 不作处理" + billDetail.detailTransactionID);
    }

    back();
    sleep(500)
    return billDetail.billID;
};

// ==================== 流水操作-end ====================


module.exports = {
    doToLoginStep2: doToLoginStep2,
    doToLoginStepPin: doToLoginStepPin,
    doPinInput: doPinInput,

    doToSendMoneyPage: doToSendMoneyPage,
    doToSendMoneyMobileSelectPage: doToSendMoneyMobileSelectPage,
    doToSendMoneyMobileInputPage: doToSendMoneyMobileInputPage,
    doSendMoneyInputTargetAccount: doSendMoneyInputTargetAccount,
    doSendMoneyInputTargetAmount: doSendMoneyInputTargetAmount,
    doSendMoneyConfirm: doSendMoneyConfirm,
    doSendMoneyInputPassword: doSendMoneyInputPassword,
    doSendMoneySuccessDone: doSendMoneySuccessDone,
    doSendMoneyFailDone: doSendMoneyFailDone,

    doToBillListPage: doToBillListPage,
    doGetBillDetails: doGetBillDetails,
    doGetAllBillsForFirstScreen:doGetAllBillsForFirstScreen,

    doGetBillsForCurrentScreen: doGetBillsForCurrentScreen,
    doScanBillsForEachScreen: doScanBillsForEachScreen
};